<template>
  <view class="wrap">
    <view class="hd">
      <view class="icon">
        <image src="../../static/time.png" class="img"></image>
      </view>
      <view class="font">待付款</view>
    </view>
    <view class="user">
      <view class="avatar">
        <image :src="setUrl(body.logo_image)" mode="aspectFill" class="img"></image>
      </view>
      <view class="right">
        <view class="title">{{ body.name }}</view>
        <view class="coin">{{ body.coin }}投研币</view>
      </view>
    </view>
    <view class="line">
      <uv-line color="#979797"></uv-line>
    </view>
    <view class="disWord" v-if="mul(body.discount_ratio, 100)">享受优惠：提前续费享【{{ mul(body.discount_ratio, 10) }}】折优惠</view>
    
    <view class="footer">
      <view class="desc">合计：<text class="red">{{ body.coin }}</text> 投研币</view>
      <view class="last">当前账户余额{{ userInfo.coin }}投研币</view>
      <button class="btn" hover-class="none" v-if="body.coin > userInfo.coin" @click="goMoneyUp">余额不足，去充值</button>
      <button class="btn" hover-class="none" v-else @click="goPay">去支付</button>
      <uv-safe-bottom></uv-safe-bottom>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { post } from '@/api';
import { useUser, useOrder } from '@/store';
import { setUrl, toast, mul, getGroup, getUser } from '@/common';

let id = '';
let content = '';
const userInfo = computed(() => {
  const store = useUser();
  return store.userInfo;
});
let body = computed(() => {
  const store = useOrder();
  return store.group;
});

onLoad((option) => {
  if(option.content){
    content = option.content;
  }
})

function goPay(){
  // 是否为空
  if(uni.$uv.test.empty(content)){ // 续费
    post('api/association_member/memberRenew', { association_id: body.value.id }).then(res => {
      if(res.code == 1){
        getUser();
        getGroup(body.value.id);
        uni.navigateTo({
          url: '/pages/success'
        });
      }
    })
  }else{ // 申请加入
    const params = {
      association_id: body.value.id,
      content: content
    }
    post("api/association/applyAssociation", params).then(res => {
      if(res.code == 1){
        getUser();
        getGroup(body.value.id);
        uni.redirectTo({
        	url: '/pages/success'
        });
      }
    })
  }
}
function goMoneyUp(){
  uni.navigateTo({
    url: '/pages/mine/money/topup',
  });
}
</script>

<style lang="scss" scoped>
  .footer{
    width: 100%;
    position: fixed;
    left: 0;
    bottom: 0;
    background-color: #fff;
    padding: 30rpx;
    .last{
      font-weight: 400;
      font-size: 24rpx;
      color: rgba(43, 43, 43, 0.46);
      text-align: center;
      padding-top: 17rpx;
      padding-bottom: 50rpx;
    }
    .desc{
      color: #2b2b2b;
      font-size: 28rpx;
      text-align: center;
      .red{
        color: #e43222;
        font-weight: 600;
      }
    }
    .btn{
      width: 432rpx;
      height: 72rpx;
      line-height: 72rpx;
      margin: 0 auto;
    }
  }
  .case{
    padding: 0 30rpx;
    padding-top: 26rpx;
    display: flex;
    align-items: center;
    .input{
      height: 72rpx;
      background: #FFFFFF;
      border: 1rpx solid #E8E8E8;
      border-radius: 4rpx;
      flex: 1;
    }
    .font{
      font-weight: 400;
      font-size: 26rpx;
      color: #797979;
      line-height: 60rpx;
    }
  }
  .integral{
    font-weight: 400;
    font-size: 22rpx;
    color: #E43222;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .disWord{
    font-weight: 400;
    font-size: 26rpx;
    color: #797979;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .line{
    padding: 0 30rpx;
    width: 100%;
  }
  .user{
    padding: 0 30rpx;
    padding-bottom: 50rpx;
    display: flex;
    align-items: center;
    .right{
      padding-left: 20rpx;
      .coin{
        font-weight: 400;
        font-size: 26rpx;
        color: #E43222;
      }
      .title{
        font-weight: 400;
        font-size: 32rpx;
        color: #2B2B2B;
        padding-bottom: 10rpx;
      }
    }
    .avatar{
      width: 100rpx;
      height: 100rpx;
      border-radius: 10rpx;
      overflow: hidden;
    }
  }
  .hd{
    padding: 0 30rpx;
    width: 100%;
    display: flex;
    align-items: center;
    padding-top: 45rpx;
    padding-bottom: 26rpx;
    .font{
      font-weight: 500;
      font-size: 30rpx;
      color: #000000;
      padding-left: 15rpx;
    }
    .icon{
      width: 30rpx;
      height: 30rpx;
      font-size: 0;
    }
  }
</style>